package com.hr.异步调用;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @program: leetcode
 * @description: 锁超时
 * @author: HuRan QQ1345122890
 * @create: 2021-08-17 10:12
 */
@Slf4j
public class ReentrantLockTest01 {
    private static ReentrantLock lock = new ReentrantLock();

    public static void main(String[] args) {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                log.info("尝试获取锁");
                if (!lock.tryLock()) {
                    log.debug("获取不到锁");
                    return;
                }
                try {
                    log.info("获取到锁");
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    lock.unlock();
                }
            }
        });
        t1.start();
    }
}